FIX Auto-wrap synchronous token providers for AsyncOpenAI compatibility#1327
Merged
FIX Auto-wrap synchronous token providers for AsyncOpenAI compatibility#1327
Conversation
Co-authored-by: romanlutz <[email protected]>
Co-authored-by: romanlutz <[email protected]>
Copilot
AI
changed the title
[WIP] Fix bug with synchronous token providers for Entra auth
Auto-wrap synchronous token providers for AsyncOpenAI compatibility
Jan 25, 2026
Contributor
|
need to validate with integration test locally |
romanlutz
approved these changes
Jan 27, 2026
Contributor
romanlutz
left a comment
There was a problem hiding this comment.
Amazingly, this works exactly as described and integration tests pass.
jbolor21
approved these changes
Jan 27, 2026
jsong468
approved these changes
Jan 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Users attempting to use
get_bearer_token_provider(DefaultAzureCredential(), scope)with OpenAI targets encounterTypeError: object str can't be used in 'await' expression. The OpenAI SDK'sAsyncOpenAIrequires async token providers, but Azure'sget_bearer_token_providerreturns synchronous callables.Changes
Added
_ensure_async_token_provider()inopenai_target.pyasyncio.iscoroutinefunction()Integrated into
OpenAITarget.__init__()api_keyparameter after environment/parameter resolutionUpdated type hints and docstrings
api_key: Optional[str | Callable[[], str | Awaitable[str]]]Added test coverage
Result
Both sync and async token providers now work transparently:
Original prompt
This section details on the original issue you should resolve
<issue_title>BUG Entra auth with synchronous token providers</issue_title>
<issue_description>#### Is your feature request related to a problem? Please describe.
Since we now support auth token providers via the
api_keyargument just like the openai SDK it is somewhat unintuitive that synchronous ones won't work. There's a cryptic error being shown if you try that.E.g., people may try the following with any openai target:
which for me yields